Ext.define('DCApp.store.Navigation', {
    extend: 'Ext.data.TreeStore',
    alias: 'store.navigation',

    constructor: function(config) {
        var me = this,
            queryParams = Ext.Object.fromQueryString(location.search),
            charts = ('charts' in queryParams) && !/0|false|no/i.test(queryParams.charts);

        me.callParent([Ext.apply({
            root: {
                text: '全部',
                id: 'all',
                expanded: true,
                children:  me.getNavItems()
            }
        }, config)]);
    },

    addIconClasses: function (items) {
        for (var item, i = items.length; i-- > 0; ) {
            item = items[i];

            if (!('iconCls' in item)) {
                item.iconCls = 'icon-' + item.id;
            }

            if (!('glyph' in item)) {
                // sets the font-family
                item.glyph = '32@Sencha-Examples';
            }

            if (item.children) {
                this.addIconClasses(item.children);
            }
        }

        return items;
    },


    getNavItems: function() {
        return this.addIconClasses([
            {
                id: 'dg_zy',
                expanded: true,
                text: '地图',
                leaf: false,
                description: '包括用于网站群的各种资源',
                children: [
                    {id: 'imglist', text: '影像', leaf: true },
                    {id: 'emap', text: '蠕虫态势', leaf: true }
                ]
            }, 
            { id: 'dg_yw_wg', text: '英文文稿', leaf: true },
                                            
            {
                text: '宁夏',
                id: 'nx',
                expanded: true,
                children: [
                    { id: 'nx_yc', 
                    	text: '银川市', 
                    	leaf: false,
                    	description: '本系统涉及的用户',
                        children: [
                           {id: 'nx_yc_xqq', text: '兴庆区', leaf: false,
	                           children: [
	                           {text: '10.1.1.1', leaf: true },
	                           {text: '10.1.1.2', leaf: true },
	                           {text: '10.1.1.3', leaf: true },
	                           {text: '10.1.1.4', leaf: true }
	                       	] 
	                       },
                           {id: 'nx_yc_jfq', text: '金凤区', leaf: false,
	                           children: [
	                           {text: '10.1.2.1', leaf: true },
	                           {text: '10.1.2.2', leaf: true },
	                           {text: '10.1.2.3', leaf: true },
	                           {text: '10.1.2.4', leaf: true }
	                       	] },
                           {id: 'nx_yc_xxq', text: '西夏区', leaf: false,
	                           children: [
	                           {text: '10.1.3.1', leaf: true },
	                           {text: '10.1.3.2', leaf: true },
	                           {text: '10.1.3.3', leaf: true },
	                           {text: '10.1.3.4', leaf: true }
	                       	]  },
                           {id: 'nx_yc_lws', text: '灵武市', leaf: true }
                       ] 
                    },
                    { id: 'nx_szs', 
                    	text: '石嘴山市', 
                    	leaf: false,
                        children: [
                           {id: 'nx_szs_dwkq', text: '大武口区', leaf: true },
                           {id: 'nx_szs_hnq', text: '惠农区', leaf: true },
                           {id: 'nx_szs_plx', text: '平罗县', leaf: true }
                       ] 
                    }
                ]
            }
        ]);
    }
});
